@import '../../styles/variables.less';

.button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  font-weight: 400;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  outline: none;
  
  // 重置按钮样式
  background: none;
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;

  // 禁用状态
  &.button-disabled {
    cursor: not-allowed;
    opacity: 0.6;
    
    &:hover,
    &:focus {
      opacity: 0.6;
    }
  }

  // 加载状态
  &.button-loading {
    pointer-events: none;
    
    .button-loading-icon {
      display: inline-flex;
      align-items: center;
      margin-right: 8px;
      animation: rotate 1s linear infinite;
      
      svg {
        width: 14px;
        height: 14px;
      }
    }
  }

  // 块级显示
  &.button-block {
    display: flex;
    width: 100%;
  }

  // 尺寸
  &.button-small {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: var(--border-radius-sm);
    
    .button-icon {
      margin-right: 4px;
    }
  }

  &.button-medium {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: var(--border-radius-base);
    
    .button-icon {
      margin-right: 8px;
    }
  }

  &.button-large {
    padding: 12px 24px;
    font-size: 16px;
    border-radius: var(--border-radius-base);
    
    .button-icon {
      margin-right: 8px;
    }
  }

  // 形状
  &.button-circle {
    border-radius: 50%;
    
    &.button-small {
      width: 32px;
      height: 32px;
      padding: 0;
    }
    
    &.button-medium {
      width: 40px;
      height: 40px;
      padding: 0;
    }
    
    &.button-large {
      width: 48px;
      height: 48px;
      padding: 0;
    }
  }

  &.button-round {
    border-radius: 40px;
  }

  // 类型
  &.button-default {
    color: var(--text-color);
    background-color: var(--bg-color-component);
    border-color: var(--border-color);
    
    &:hover:not(.button-disabled) {
      color: var(--primary-color);
      border-color: var(--primary-color);
    }
    
    &:focus:not(.button-disabled) {
      outline: 2px solid rgba(24, 144, 255, 0.2);
    }
  }

  &.button-primary {
    color: #fff;
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    
    &:hover:not(.button-disabled) {
      background-color: #40a9ff;
      border-color: #40a9ff;
    }
    
    &:focus:not(.button-disabled) {
      outline: 2px solid rgba(24, 144, 255, 0.2);
    }
  }

  &.button-success {
    color: #fff;
    background-color: var(--success-color);
    border-color: var(--success-color);
    
    &:hover:not(.button-disabled) {
      background-color: #73d13d;
      border-color: #73d13d;
    }
  }

  &.button-warning {
    color: #fff;
    background-color: var(--warning-color);
    border-color: var(--warning-color);
    
    &:hover:not(.button-disabled) {
      background-color: #ffa940;
      border-color: #ffa940;
    }
  }

  &.button-error {
    color: #fff;
    background-color: var(--error-color);
    border-color: var(--error-color);
    
    &:hover:not(.button-disabled) {
      background-color: #ff4d4f;
      border-color: #ff4d4f;
    }
  }

  &.button-dashed {
    color: var(--text-color);
    background-color: var(--bg-color);
    border: 1px dashed var(--border-color);
    
    &:hover:not(.button-disabled) {
      color: var(--primary-color);
      border-color: var(--primary-color);
    }
  }

  &.button-text {
    color: var(--text-color);
    background-color: transparent;
    border: none;
    
    &:hover:not(.button-disabled) {
      background-color: var(--bg-color-component);
    }
  }

  &.button-link {
    color: var(--primary-color);
    background-color: transparent;
    border: none;
    
    &:hover:not(.button-disabled) {
      color: #40a9ff;
      text-decoration: underline;
    }
  }

  // 仅图标按钮
  &.button-icon-only {
    .button-icon {
      margin-right: 0;
    }
  }

  // 图标和内容
  .button-icon {
    display: inline-flex;
    align-items: center;
    line-height: 1;
  }

  .button-content {
    line-height: 1;
  }
}

// 旋转动画
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}